<template>
	<view class="box" v-if="is==0">
		<view class="" style="position: relative;">
			<image src="https://web.78keji.cn/lxnimgs/ljj.png" mode="widthFix" style="width: 100%;">
			</image>
			<view class="" style="position: absolute;margin-top: -300rpx;width: 100%;padding:0 80rpx;" v-if="showss">
				<u-form style="">
					<u-form-item>
						<u-input v-model="yinhang" placeholder="选择立减金类型" type="select" @click='shows=true'
							placeholder-style="corlor:#999999" />
					</u-form-item>
				</u-form>
			</view>

			<u-select v-model="shows" :list="listx" @confirm="confirm" title="选择发放立减金银行" v-if="showss"></u-select>

		</view>
		<view class="d_f j_c_c" style="width: 100%;">

			<u-button type="success" shape="circle"
				style="position: absolute;width:664rpx;height: 97rpx;margin-top: 6rpx;top: 500rpx;" 
				@click="lq" v-if="showss">立即领取</u-button>
			<u-button type="success" shape="circle"
				style="position: absolute;width:664rpx;height: 97rpx;margin-top: 6rpx;top: 500rpx;" 
				 v-else>已领取</u-button>
			<image src="https://web.78keji.cn/images/lxn/dp.png" mode="widthFix"
				style="width: 94%;position: absolute;top: 650rpx;" @click="changex"></image>
			<view class="" style="height: 100rpx;">

			</view>

		</view>






	</view>
</template>

<script>
	import {
		sendSms,
		checkSms,
		ljjList,
		wxLogins,
		ljjLq,
		getshenhe,
		getPhone,
		tclGetExtraData,
	
	} from '../../api/index.js'
	import {
	
		page,
		login,
		tcllq,
		grantEquity
		
	} from '../../api/indexv2.js'

	import moment from '../../utils/moment.js'
	export default {
		data() {
			return {
				yinhang: '',
				shows: false,
				is: '',
				content: '',
				border: true,
				showx: false,
				orderNo:"",
				listx: [





				],
				// u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
				value: '',
				shows: false,
				list: [{
					name: '喜马拉雅'
				}, {
					name: '省心会员'
				}],
				current: 0,
				mobile: "",
				show: false,
				code: "",
				getCodeText: '获取验证码',
				getCodeBtnColor: "#ffffff",
				getCodeisWaiting: false,
				disabled: false,
				openid: "", //是否登录
				proType: '15',
				xmlydata: [{
					money: 5,
					status: "0",
					starttime: '2024.01.01',
					endtime: "2099.01.01"

				}],
				tldata: [],
				ljjid: "", //立减金id
				idx: "", //省心会员券id
				proOrder: "",
				id: "",
				annualPayNum: '',
				showss:false,



			}
		},
		components: {

		},
		methods: {
			changex() {
			console.log(77)
					grantEquity({
						orderNo: this.orderNo,
						annualPayNum: this.annualPayNum,
						id:this.id
					}).then((res) => {
						console.log(res)
						uni.showToast({
							title:res.message,
							icon: "none"
						}); //弹出提示框

					})
				



			},
			confirm(e) {
				console.log(e);
				this.yinhang = e[0].label
				// this.value = e[0].value

			},
			getphonenumber(e) {
				
				if(this.listx.length>0){
					if (this.yinhang == '') {
						uni.showToast({
							title: '请先选择银行',
							icon: "none"
						}); //弹出提示框
					} else {
					
						for (var i in this.listx) {
							console.log(this.listx)
							if (this.yinhang == this.listx[i].label) {
								tcllq({
									id: this.id,
									annualPayNum: this.annualPayNum,
									receiveType: this.listx[i].receiveType,
									receiveValue: this.listx[i].value
					
								}).then((res) => {
									uni.navigateTo({
										url: '/pages/result/result?flag=1'
									})
								})
							}
						}
					
					}
				}else{
				uni.showToast({
					title: '暂无可领取立减金',
					icon: "none"
				}); //弹出提示框	
				}
			
				//调用自己后台接口获取手机号
			},
			lq() {
	this.getphonenumber()

			},
			one() {
				uni.login({
					provider: 'weixin', //使用微信登录
					success: function(loginRes) {
						console.log(loginRes.code);
						// uni.setStorageSync('codexs', loginRes.code)
						getPhone({
							openid: uni.getStorageSync('openidHF'),
							code: loginRes.code
						}).then((res) => {
							console.log(res)
						})

					}
				});

			},
			add(item) {
				this.shows = true
				this.ljjid = item


			},
			viplq(item) {
				this.showx = true
				this.idx = item
			},

			lingqus() {

				uni.showLoading({
					title: '领取中，请稍等',
					mask: true
				});
				ljjLq({
					openid: this.openid,
					type: 3,
					id: this.ljjid,
					account: uni.getStorageSync('openidHF'),
					accountType: 3,
					bankType: this.value

				}).then((res) => {
					uni.showToast({
						title: res.msg,
						icon: "none"
					}); //弹出提示框
					this.getdata()
				})
			},
			change(index) {
				if (!uni.getStorageSync('openid')) {
					uni.showToast({
						title: '请先登录',
						icon: "none"
					}); //弹出提示框

				} else {
					this.current = index;
					this.getdata()
				}

			},
			//推出登录
			loginout() {
				uni.clearStorage()
				this.openid = ''
				this.xmlydata = []
				this.tldata == []
			},
			//获取验证码
			getCode() {
				sendSms({
					mobile: this.mobile,

				}).then((res) => {
					this.disabled = true
					this.getCodeText = "发送中..." //发送验证码
					this.getCodeisWaiting = true;
					setTimeout(() => {
						//this.$common.msg('验证码已发送')
						uni.showToast({
							title: '验证码已发送',
							icon: "none"
						}); //弹出提示框
						this.setTimer(); //调用定时器方法
					}, 1000)
				})
			},
			setTimer() {
				let holdTime = 60; //定义变量并赋值
				this.getCodeText = "重新获取(60)"
				//setInterval（）是一个实现定时调用的函数，可按照指定的周期（以毫秒计）来调用函数或计算表达式。
				//setInterval方法会不停地调用函数，直到 clearInterval被调用或窗口被关闭。
				this.Timer = setInterval(() => {
					if (holdTime <= 0) {
						this.disabled = false
						this.getCodeisWaiting = false;
						this.getCodeBtnColor = "#ffffff";
						this.getCodeText = "获取验证码"
						clearInterval(this.Timer); //清除该函数
						return; //返回前面
					}
					this.getCodeText = "重新获取(" + holdTime + ")"
					holdTime--;
				}, 1000)
			},
			gets(){
				page({
					page: 1,
					pageSize: 100,
					condition: {}
				}).then((res) => {
					if(res.data.records[0].receiveStatus=='2'||res.data.records[0].receiveStatus=='3'){
						this.showss=false
					}else if(res.data.records[0].receiveStatus=='1'||res.data.records[0].receiveStatus=='4'){
						this.showss=true
					}
					this.id = res.data.records[0].id
					this.annualPayNum = res.data.records[0].annualPayNum
					this.orderNo = res.data.records[0].orderNo
					
					console.log(res.data.records[0].equityPortfolioConfigList)
					
					let a = ["equityCode", "label", "receiveType", 'value'];
					let b = res.data.records[0].equityPortfolioConfigList
					console.log('要转化的数据：\n', b)
					//item 数组的每一个对象、index 数组下标、arr 即数组b
					let c = b.map((item, index, arr) => {
						let obj = {};
						var mm1 = 0;
						for (let i in item) {
							if (mm1 < a.length) {
								obj[a[mm1]] = item[i];
								mm1++;
							} else {
								//如果不需要可以不写
								obj[i] = item[i];
							}
						}
						return obj;
					});
					console.log('结果：\n', c);
					this.listx = c
				}).catch((err) => {
				
				})
			},
			getdata() {
				if (!uni.getStorageSync('tokens')) {
					
					uni.login({
						provider: 'weixin',
						success:(res) => {
							if (res.code) {
								let that =this
								 wx.getUserInfo({
									 success(rex){
										
										 login({
										 	code: res.code,
										 	appId: 'wx8b15dc2c1ee47c1f',
										 	encryptedData:rex.encryptedData,
											iv:rex.iv
										 }).then((resx) => {
										 	console.log(resx.data.accessToken)
										 	uni.setStorageSync('tokens', resx.data.accessToken)
										 	uni.setStorageSync('uniqueUserId', resx.data.uniqueUserId)
										that.gets()
										 })
									 }
								 })
							
							} 
						}
					})
				
				}else{
				this.gets()
				}
			


			},


			//点击登录
			login() {
				if (this.code == '') {
					uni.showToast({
						icon: 'none',
						title: '请输入验证码',
						duration: 2000
					});
				} else if (this.mobie == '') {
					uni.showToast({
						icon: 'none',
						title: '请输入手机号',
						duration: 2000
					});
				} else {
					checkSms({
						mobile: this.mobile,
						captcha: this.code,
						type: 3
					}).then((res) => {
						this.show = false
						uni.setStorageSync('openid', res.data.openid)
						uni.setStorageSync('mobile', res.data.mobile)
						this.openid = uni.getStorageSync('openid')
						this.mobile = uni.getStorageSync('mobile')
						this.getdata()
					})
				}

			}
		},
		onLoad() {

			this.getdata()
			if (uni.getStorageSync('mobile')) {
				this.mobile = uni.getStorageSync('mobile')

			}
	


		},
		watch: {

		},
		computed: {

		}
	}
</script>

<style scoped lang='scss'>
	.money {
		font-size: 90rpx;
	}

	.unit {
		margin-top: 70rpx;
	}

	.box {
		background-color: #FFF0E3;
		min-height: 110vh;
		padding: 24rpx 24rpx 0 24rpx;
	}

	.title {

		font-size: 34rpx;

		font-weight: 400;
		color: #1A1A1A;
		margin-top: 50rpx;

	}

	.boss {
		background-color: white;
		width: 662rpx;

		margin: 0 auto;

		text-align: center;
		position: relative;


	}
</style>
